package com.zf.apartment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import com.zf.apartment.domain.Room;
import com.zf.apartment.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zf.apartment.mapper.FlatsRoomMapper;
import com.zf.apartment.domain.FlatsRoom;
import com.zf.apartment.service.IFlatsRoomService;

/**
 * 公寓和房间关系Service业务层处理
 *
 * @author rxf
 * @date 2024-10-02
 */
@Service
public class FlatsRoomServiceImpl extends ServiceImpl<FlatsRoomMapper, FlatsRoom> implements IFlatsRoomService {
    @Autowired
    private FlatsRoomMapper flatsRoomMapper;
    @Autowired
    private RoomMapper roomMapper;
    /**
     * 查询公寓和房间关系
     *
     * @param flatsId 公寓和房间关系主键
     * @return 公寓和房间关系
     */
    @Override
    public List<FlatsRoom> selectFlatsRoomByFlatsId(Long flatsId) {
        //先查看这个返回值都有什么
        List<FlatsRoom> fr= flatsRoomMapper.selectFlatsRoomByFlatsId(flatsId);
        return fr;
    }

    /**
     * 查询公寓和房间关系列表
     *
     * @param flatsRoom 公寓和房间关系
     * @return 公寓和房间关系
     */
    @Override
    public List<FlatsRoom> selectFlatsRoomList(FlatsRoom flatsRoom) {
        return flatsRoomMapper.selectFlatsRoomList(flatsRoom);
    }

    /**
     * 新增公寓和房间关系
     *
     * @param flatsRoom 公寓和房间关系
     * @return 结果
     */
    @Override
    public int insertFlatsRoom(FlatsRoom flatsRoom) {
            return flatsRoomMapper.insertFlatsRoom(flatsRoom);
    }

    /**
     * 修改公寓和房间关系
     *
     * @param flatsRoom 公寓和房间关系
     * @return 结果
     */
    @Override
    public int updateFlatsRoom(FlatsRoom flatsRoom) {
        return flatsRoomMapper.updateFlatsRoom(flatsRoom);
    }

    /**
     * 批量删除公寓和房间关系
     *
     * @param flatsIds 需要删除的公寓和房间关系主键
     * @return 结果
     */
    @Override
    public int deleteFlatsRoomByFlatsIds(Long[] flatsIds) {
        return flatsRoomMapper.deleteFlatsRoomByFlatsIds(flatsIds);
    }

    /**
     * 删除公寓和房间关系信息
     *
     * @param flatsId 公寓和房间关系主键
     * @return 结果
     */
    @Override
    public int deleteFlatsRoomByFlatsId(Long flatsId) {
        return flatsRoomMapper.deleteFlatsRoomByFlatsId(flatsId);
    }

    @Override
    public FlatsRoom selectFlatsRoomByRoomId(Long roomId) {
        return flatsRoomMapper.selectFlatsRoomByRoomId(roomId);
    }

    @Override
    public void deleteFlatsRoomByRoomIds(Long[] roomIds) {}

    @Override
    public void deleteFlatsRoomByRoomId(Long roomId) {}

    @Override
    public int updateFlatsRoomByRoom(FlatsRoom flatsRoom) {
        return flatsRoomMapper.updateFlatsRoomByRoom(flatsRoom);
    }

    @Override
    public List<Room> selectRoomList(Long flatsId) {
        List<Room> roomList = new ArrayList<>();
        for(FlatsRoom flatRoom : selectFlatsRoomByFlatsId(flatsId)){
            roomList.add(roomMapper.selectRoomByRoomId(flatRoom.getRoomId()));
        }
        return roomList;
    }
}